﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace KduneeShaders.PostProcess
{
    /// <summary>
    /// Shader implementujący rozmycie
    /// </summary>
    public class BlurPostProcessExtended : PostProcessShader
    {
        /// <summary>
        /// Rozmiar rozmycia
        /// </summary>
        public float Blur
        {
            get { return effect.Parameters["BlurDistance"].GetValueSingle(); }
            set { effect.Parameters["BlurDistance"].SetValue(value); }
        }

        private BlurPostProcess[] effects = null;
        public BlurPostProcessExtended(int passes)
        {
            effects = new BlurPostProcess[passes];
            for (int i = 0; i < effects.Length; i++) effects[i] = new BlurPostProcess();
        }

        /// <summary>
        /// Przygotuj shader do działania
        /// </summary>
        /// <param name="graphics">Menadżer wyświetlania</param>
        /// <param name="content">Menadżer danych</param>
        override public void Prepare(GraphicsDeviceManager graphics, ContentManager content)
        {
            for (int i = 0; i < effects.Length; i++) effects[i].Prepare(graphics, content);
        }

        /// <summary>
        /// Wykonaj operacje niezbędne przed renderingiem sceny
        /// </summary>
        /// <param name="graphics">Menadżer wyświetlania</param>
        public override void PreRender(GraphicsDeviceManager graphics)
        {
            for (int i = 0; i < effects.Length; i++) effects[i].PreRender(graphics);
        }

        /// <summary>
        /// Wykonaj operacje niezbędne po renderingu sceny
        /// </summary>
        /// <param name="graphics">Menadżer wyświetlania</param>
        public override void PostRender(GraphicsDeviceManager graphics)
        {
            for (int i = effects.Length - 1; i >= 0; i--) effects[i].PostRender(graphics);
        }

    }
}
